package org.dromara.mall.service.impl;

import lombok.RequiredArgsConstructor;
import org.dromara.mall.domain.MallCateBrand;
import org.dromara.mall.domain.MallGoodsSpecVal;
import org.dromara.mall.mapper.MallGoodsSpecValMapper;
import org.dromara.mall.service.IMallGoodsSpecValService;
import org.springframework.stereotype.Service;

import java.util.Collection;


/**
 * 商品规格Service业务层处理
 *
 * @author Lion Li
 * @date 2024-05-20
 */
@RequiredArgsConstructor
@Service
public class MallGoodsSpecValServiceImpl implements IMallGoodsSpecValService {

    private final MallGoodsSpecValMapper baseMapper;


    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if (isValid) {
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        // 删除
        return baseMapper.deleteBatchIds(ids) > 0;
    }
    /*增加*/
    @Override
    public Boolean insertByBo(MallGoodsSpecVal bo) {
        //做一些业务上的校验
        validEntityBeforeSave(bo);
        return baseMapper.insert(bo) > 0;
    }

    /*编辑*/
    @Override
    public Boolean updateByBo(MallGoodsSpecVal bo) {
        validEntityBeforeSave(bo);
        //TODO 做一些业务上的校验
        return baseMapper.updateById(bo) > 0;
    }
    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(MallGoodsSpecVal entity){
        System.out.println("校验"+entity.toString());
        // 校验name不为空
        if (entity.getName() == null || entity.getName().trim().isEmpty()) {
            throw new IllegalArgumentException("属性名称不能为空");
        }
        // 校验specId不为空
        if (entity.getSpecId() == null) {
            throw new IllegalArgumentException("specId不能为空");
        }
    }


}
